#include "chessPieces.h"

ChessPieces::ChessPieces() {
    row = -1;
    col = -1;
    id = -1;
    dead = true;
    red = true;
    type = PIECES_TYPE::UnKnow;
}

// 棋子初始化
void ChessPieces::init(int id, bool redTopBlackBottom)
{
    this->id = id;
    this->dead = false;
    // 如果为红上黑下，则红方编号小于16，黑方编号大于16
    // 如果为黑上红下，则黑方编号小于16，红方编号大于16
    this->red = redTopBlackBottom ? id < 16 : id >= 16;

    if(id < 16) {
        this->row = board_attr[id].row;
        this->col = board_attr[id].col;
        this->type = board_attr[id].type;
    } else {
        this->row = (BOARD_ROW_NUM - 1) - board_attr[id - PIECES_NUM / 2].row;
        this->col = (BOARD_COL_NUM - 1) - board_attr[id - PIECES_NUM / 2].col;
        this->type = board_attr[id - PIECES_NUM / 2].type;
    }
}

QString ChessPieces::getText() const {
    switch (this->type) {
    case PIECES_TYPE::CHE:
        return "车";
    case PIECES_TYPE::BING:
        return this->red ? "兵" : "卒";
    case PIECES_TYPE::JIANG:
        return this->red ? "帅" : "将";
    case PIECES_TYPE::MA:
        return "马";
    case PIECES_TYPE::PAO:
        return "炮";
    case PIECES_TYPE::SHI:
        return "士";
    case PIECES_TYPE::XIANG:
        return this->red ? "相" : "象";
    default:
        return "未知";
    }
}
